package com.haoxi.gateway.smgpmsg;

import com.haoxi.gateway.util.TypeConvert;

public class SMGPLoginRespMessage extends SMGPMessage {

    public SMGPLoginRespMessage(byte buf[]) throws IllegalArgumentException {
        super.buf = new byte[25];
        if (buf.length != 25) {
            throw new IllegalArgumentException(
                    "The message that is sent by SMC is wrong");
        } else {
            System.arraycopy(buf, 0, super.buf, 0, buf.length);
            sequence_Id = TypeConvert.byte2int(super.buf, 0);
            return;
        }
    }

    public int getStatus() {
        return TypeConvert.byte2int(buf, 4);
    }

    public byte[] getAuthenticatorServer() {
        byte tmpbuf[] = new byte[16];
        System.arraycopy(buf, 8, tmpbuf, 0, 16);
        return tmpbuf;
    }

    public byte getVersion() {
        return buf[24];
    }

    public String toString() {

        StringBuffer strBuf = new StringBuffer();
        strBuf.append("SMGPLoginRespMessage: ");
        strBuf.append("PacketLength=").append(buf.length);
        strBuf.append(",RequestID=").append("0x").append(
                Integer.toHexString(getRequestId()));
        strBuf.append(",Sequence_Id=").append(getSequenceId());
        strBuf.append(",Status=").append(getStatus());
        strBuf.append(",AuthenticatorServer=".concat(String.valueOf(String
                .valueOf(new String(getAuthenticatorServer())))));
        strBuf.append(",Version=".concat(String.valueOf(String
                .valueOf(getVersion()))));
        return strBuf.toString();
    }

    public int getRequestId() {
        return SMGPCommon.SMGP_LOGIN_RESP;
    }
}
